package com.qpf.mycms.api.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.util.Date;

@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {

    public static final String CREATE_TIME_FIELD = "createTime";
    public static final String UPDATE_TIME_FIELD = "updateTime";
    public static final String DEL_FLAG_FIELD = "delFlag";

    @Override
    public void insertFill(MetaObject metaObject) {
        strictInsertFill(metaObject, CREATE_TIME_FIELD, Date.class, new Date());
        strictInsertFill(metaObject, UPDATE_TIME_FIELD, Date.class, new Date());
        strictInsertFill(metaObject, DEL_FLAG_FIELD, Integer.class, 0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        strictUpdateFill(metaObject, UPDATE_TIME_FIELD, Date.class, new Date());
    }
}
